package br.com.bikerz.user.service;

import br.com.bikerz.user.dao.UserDAO;
import br.com.bikerz.user.domain.User;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("userService")
public class UserServiceImpl implements UserService{

	private UserDAO userDAO;

	@Autowired
	public UserServiceImpl(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	@Transactional
	public void createNew(User user) {
		userDAO.persist(user);
	}

	@Transactional(readOnly=true)
	public List<User> findAll() {
		return userDAO.loadAll();
	}

	@Transactional(readOnly=true)
	public List<User> findByTitle(String title) {
		return userDAO.findByTitle(title);
	}

	@Transactional
	public void update(User user) {
		userDAO.update(user);
	}

	@Transactional
	public void remove(User user) {
		userDAO.delete(user);
	}

	@Transactional(readOnly=true)
	public User findById(Long id) {
		return userDAO.loadById(id);
	}
}
